import router from "@/router"
import { useUsersStore } from "./stores/user"

const whiteList = ["/login", "/404"]
/**
 * to 到哪里去
 * from 从哪里来
 * next 你确定要去吗？
 */
router.beforeEach((to, from, next) => {
  const userStore = useUsersStore()
  console.log(userStore.token)
  // 有无token：有=登录 无=未登录
  if (userStore.token) {
    // console.log(userStore.token)
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }

  }
})

